<?php
/**
 * Created by PhpStorm.
 * User: Guangpeng Chen
 * Date: 15-7-31
 * Time: 下午3:27
 */
include '../common/func.inc.php';
//get
$topic = file_get_contents('../common/topic.txt');
//echo $topic;
$topic_arr = explode(":", $topic);
if ($_SERVER['REQUEST_METHOD']=='GET') {
    echo json_encode(array('code'=>'200', 'collection'=>$topic_arr));
}
elseif ($_SERVER['REQUEST_METHOD']=='POST') {
    $topic = safetxt($_POST['topic']);
    if (!in_array($topic, $topic_arr)) {
        file_put_contents('../common/topic.txt', ':'.$topic, FILE_APPEND);
    }
    echo '{"code":200}';
}